$(function () {
    // alert("sa");
    var totalPage = $('span#totalPage').text();
    var userName = $('#exampleInputName2').val();
    var a = parseInt(totalPage);
    if (a > 0) {
        $('#pagination-demo').twbsPagination({
            totalPages: a,
            visiblePages: 5,
            first: '首页',
            prev: "<<",
            next: '>>',
            last: '最后一页',
            onPageClick: function (event, page) {
                event.preventDefault();
                $.ajax({
                    type: 'post',
                    url: '/charge/viewdetaillist',
                    data: {
                        pageIndex: page,
                        condition: userName
                    },
                    dataType:'json',
                    success: function (data) {
                        if (data.status==1) {
                            var str = "";
                            var promx = data.data;
                            console.log(promx);
                            for (var i = 0; i < promx.list.length; i++) {
                                str += "<tr>\n" +
                                    " \t<td><input type='checkbox' name='ids' value='" + promx.list[i].id + "'></td>\n" +
                                    " <td>" + (i + 1) + "</td>\n" +
                                    " <td>" + promx.list[i].village + "</td>\n" +
                                    " <td style =''>" + promx.list[i].charge_name+ "</td>\n" +
                                    " <td style =''>" + promx.list[i].owner + "</td>\n" +
                                    " <td style =''>" + promx.list[i].ex_money + "</td>\n" +
                                    " <td style =''>" + promx.list[i].re_money + "</td>\n" +
                                    " <td style =''>" + (new Date((promx.list[i].pay_time)).Format('yyyy-MM-dd'))+ "</td>\n" +
                                    " <td style =''>" + (new Date((promx.list[i].create_time)).Format('yyyy-MM-dd hh:mm:ss'))+ "</td>\n" +
                                    " <td style ='display: none'>" + promx.list[i].id + "</td>\n" +
                                    " <td class=\"td-manage\">" +
                                    "                <a title=\"编辑\" href=\"javascript:;\" onclick=\"promx_edit('编辑','/charge/promx_edit.html/','"+promx.list[i].id+"','1000','600')\"\n" +
                                    "                   class=\"ml-5\" style=\"text-decoration:none\">\n" +
                                    "                    <i class=\"layui-icon\">&#xe642;</i>\n" +
                                    "                </a>\n" +
                                    "                <a title=\"删除\" href=\"javascript:;\" onclick=\"promx_del(this,'"+promx.list[i].id+"')\"\n" +
                                    "                   style=\"text-decoration:none\">\n" +
                                    "                    <i class=\"layui-icon\">&#xe640;</i>\n" +
                                    "                </a>" +
                                    "</td>\n" +
                                    "</tr>";
                            }
                            var trNode = $('#ulContainer');
                            trNode.html(str);

                        } else {
                            layer.msg(data.msg, {icon: 5, time: 1000});
                        }
                    },
                    error: function () {
                        swal("出现错误");
                    }
                });
            }
        });
    }

});
$(function () {
//全选全部取消-步骤（当选中前面的按钮、下面所有都被选中 反之，下面所有都被取消选中）
    $("#all").click(function(){
        if($(this).is(":checked")){ //如果被选中
            $("[name=ids]").prop("checked",true); //添加选中状态
        }else{
            $("[name=ids]").prop("checked",false);//取消选中状态
        }
    });
});
//日期格式转换
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}